package response

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func ResU(ctx *gin.Context, HttpStatus int, code int, msg string, data gin.H) {
	ctx.JSON(HttpStatus, gin.H{
		"code": code,
		"msg":  msg,
		"data": data,
	})
}

func Success(ctx *gin.Context, msg string, data gin.H) {
	ResU(ctx, http.StatusOK, 2000, msg, data)
}
func Fail(ctx *gin.Context, msg string, data gin.H) {
	ResU(ctx, http.StatusBadRequest, 4000, msg, data)
}
func CheckFail(ctx *gin.Context, msg string, data gin.H) {
	ResU(ctx, http.StatusUnprocessableEntity, 4022, msg, data)
}

// 特殊处理响应信息
func AllResponse(ctx *gin.Context, res ResponseBody) {
	ctx.JSON(res.HttpStatus, gin.H{"code": res.Code, "data": res.Data, "msg": res.Msg})
}
